package com.longrise.android.byjk.plugins.tabsecond;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.longrise.android.byjk.R;
import com.longrise.android.byjk.model.AllCourseChildBean;
import com.longrise.android.byjk.plugins.course.coursedetail.CourseDetailActivity2;
import com.longrise.android.byjk.widget.view.BBswipeRefreshLayout;
import com.longrise.common.base.BaseFragment;

import java.util.List;

/**
 * Created by callxkj on 2017/10/23.
 * 保险医学中 每个系统的详情页面
 */

public class SecondDetailFragment extends BaseFragment<SecondDetailPresenter>
        implements SwipeRefreshLayout.OnRefreshListener, SecondDetailAdapter.OnDetailItemClickListener ,SecondDetailContract.View{
    public static final String ASSORTMENTTYPEKEY = "assortmenttypekey";
    private static final String TAG = "SecondDetailFragment";
    private String mAssortmenttype;
    private BBswipeRefreshLayout mSrl;
    private RecyclerView mRcv;
    private SecondDetailAdapter mAdapter;

    @Override
    protected int getLayoutResourse(@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_seconddetail;
    }

    @Override
    public void initView() {
        mSrl = (BBswipeRefreshLayout) mRootView.findViewById(R.id.seconddetail_fragment_swipelayout);
        mRcv = (RecyclerView) mRootView.findViewById(R.id.seconddetail_fragment_irv);
        Bundle arguments = getArguments();
        mAssortmenttype = arguments.getString(ASSORTMENTTYPEKEY);
        initRcv();
        initEvent();
        mPresenter.getData(mAssortmenttype);
    }

    private void initRcv(){
        View headView = View.inflate(mContext,R.layout.item_seconddetailfragment_headview,null);
        mAdapter = new SecondDetailAdapter();
        mAdapter.addHeaderView(headView);
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        mRcv.setLayoutManager(manager);
        mRcv.setAdapter(mAdapter);
    }

    private void initEvent(){
        mSrl.setOnRefreshListener(this);
        mAdapter.setOnDetailItemClickListener(this);
    }


    @Override
    public void onRefresh() {
       mPresenter.getData(mAssortmenttype);
    }


    @Override
    public void onClick(String courseid, String realprice) {
        Intent intent = new Intent(mContext, CourseDetailActivity2.class);
        intent.putExtra(CourseDetailActivity2.INTENT_EXTRA_PARAMS, courseid);
        intent.putExtra(CourseDetailActivity2.COURSE_PRICE,realprice);
        mContext.startActivity(intent);
    }

    @Override
    public void showLoadingDialog() {

    }

    @Override
    public void dismissLoadingDialog() {

    }

    @Override
    public void refreshData(List<AllCourseChildBean> childBeanList) {
       mAdapter.setData(childBeanList);
    }

    @Override
    public void setRefreshing(boolean isRefreshing) {
       mSrl.setRefreshing(isRefreshing);
    }
}
